<?php
/**
 * Created by PhpStorm.
 * User: td
 * Date: 15/1/8
 * Time: 上午2:04
 */

namespace Home\Controller;
use Think\Controller;

class LoginController extends Controller {

    //登陆页面
    public function login(){
        if(IS_POST){
            $phone = $_POST['phone'];
            $passwd = $_POST['passwd'];
            if(NULL != $phone && NULL != $passwd){
                $user_db = D('User');
                $user_info = $user_db->getByPhone($phone);
                if($passwd == $user_info['passwd']){
                    session('loginUser',$user_info);
                    //dump($_SESSION);
                    $user_status_db = D('User_status');
                    $data['user_id'] = $user_info['user_id'];
                    ini_set('date.timezone','Asia/Shanghai');
                    $data['login_time'] = date('Y-m-d H:i:s',time());
                    $data['logout_time'] = date("Y-m-d H:i:s",strtotime("+10minutes",strtotime($data['login_time'])));
                    $data['session_id'] = session_id();

                    $result = $user_status_db->add($data);
                    //dump($result);
                    if($result){
                        $this->success("登陆成功!");
                    }else{
                        $this->error('状态存入失败!');
                    }

                }else{
                    $this->error("登陆失败!");
                }
            }else{
                $this->error("手机号或者密码为空!");
            }

        }else{
            $this->display('Login');
        }
    }


} 